"""nicegui :2.11.0"""

from fastapi.responses import PlainTextResponse
from nicegui import ui, app
from nicegui.elements.markdown import CODEHILITE_CSS_URL
from pygments.formatters import HtmlFormatter  # pylint: disable=no-name-in-module

from pygments.styles import get_all_styles

# 可选的主题列表
print(list(get_all_styles()))


def set_md_theme():
    light_style = "vs"
    dark_style = "gruvbox-dark"

    app.get(CODEHILITE_CSS_URL)(
        lambda: PlainTextResponse(
            HtmlFormatter(nobackground=True, style=light_style).get_style_defs(
                ".codehilite"
            )
            + HtmlFormatter(nobackground=True, style=dark_style).get_style_defs(
                ".body--dark .codehilite"
            ),
            media_type="text/css",
        )
    )


set_md_theme()


code = r"""
```python
import pandas as pd
print(pd.__version__)     

total = sum(range(101))
print(total)

```
"""


ui.markdown(
    code,
).classes("body--dark bg-gray-700 p-2")


ui.run()
